package com.zym.controller;

import com.zym.entity.SysRole;
import com.zym.enums.AckCode;
import com.zym.service.SysRoleService;
import com.zym.vo.R;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Api(tags = "sysRole")
@RequestMapping("/sysRole")
public class SysRoleController {
    @Autowired
    private SysRoleService sysRoleService;
    @GetMapping("/getList")
    public R getList(){
        List<SysRole> all = sysRoleService.findAll();
        return R.okHasData(all);
    }
    @PostMapping("/add")
    public R add(@RequestBody  SysRole sysRole){
        int add = sysRoleService.add(sysRole);
        if (add>0){
            return R.ok();
        }else {
            return R.build(AckCode.FAIL);
        }

    }
    @DeleteMapping ("/{id}")
    public R deleteById(@PathVariable  Long id){
        int add = sysRoleService.remove(id);
        if (add>0){
            return R.ok();
        }else {
            return R.build(AckCode.FAIL);
        }

    }
    @PutMapping  ("/modify")
    public R modify(@RequestBody SysRole sysRole){
        int add = sysRoleService.modify(sysRole);
        if (add>0){
            return R.ok();
        }else {
            return R.build(AckCode.FAIL);
        }

    }
}
